home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 002 / findasci.arc / FINDASCI.C next >
Text File  |  1987-03-18  |  3KB  |  142 lines

  1. #include "c:\lc\stdio.h"
  2.  
  3. #define DEFSEN 3
  4. #define MAXSEN 50
  5. #define CR 13
  6. #define LF 10
  7. #define TAB 9
  8. #define SPC 32
  9. #define ANULL 127
  10. #define ARROW 16
  11.  
  12. main(argc, argv)
  13. int argc;
  14. char *argv[];
  15. {
  16.     int l;
  17.     int c;
  18.     int oldc;
  19.     int cnt;
  20.     int sav[MAXSEN];
  21.     int crcount;
  22.     int sen;
  23.     int sensitivity;
  24.  
  25.  
  26.     FILE *fp, *fopen();
  27.  
  28.     sen = DEFSEN;     
  29.     cnt = 0;
  30.     crcount = 0;
  31.     c = NULL;
  32.     oldc = NULL;
  33.     l = 0;
  34.     sensitivity = atoi(argv[2]);
  35.  
  36.  
  37.     if (argc < 2 || argc > 3) {
  38.         printf ("\n");
  39.         printf ("\n    Command line format:  FINDASCI <filename> <sensitivity>\n");
  40.         printf ("\n    FINDASCI v1.1, by Peter Nelson.                        \n");
  41.         printf ("\n    This program will search through <filename>, and       \n");
  42.         printf ("    display all the ascii characters found.  <Sensitivity> \n");
  43.         printf ("    is how many CONSECUTIVE ascii characters to find before\n");
  44.         printf ("    displaying them.  The default is 3, hence HI will    \n");
  45.         printf ("    not produce any output, but MAN will produce  MAN  . \n");
  46.         printf ("    The higher the number, the less garbage you will get,  \n");
  47.         printf ("    the greater the chance of missing some data.  A lower  \n");
  48.         printf ("    number will show more data, but also more garbage.     \n");
  49.         printf ("    ENJOY!  Finis, Mongo                                 \n\n");
  50.     }
  51.    else {
  52.  
  53.         if ((fp = fopen(argv[1], "rb")) == NULL)
  54.             printf ("\nError opening file: %s\n", argv[1]);
  55.         else {
  56.  
  57.             if ((argc == 3) && (sensitivity < 1 || sensitivity > MAXSEN)) {
  58.                 printf ("\n<sensitivity> must be between 1 & %d.\n", MAXSEN);
  59.             }
  60.             else {
  61.  
  62.                 if (argc==3)
  63.                     sen = sensitivity;
  64.                 
  65.                 c = getc(fp) ;
  66.                 while    (c != EOF) {
  67.                     if ((c >= SPC && c <= ANULL) || (c==TAB) || (c==CR) || (c==LF)) {
  68.     
  69.                         if (c == LF && oldc != CR)
  70.                             c = NULL;
  71.     
  72.                         if ((c == CR) || (c == LF && oldc != CR))
  73.                             c = '\n';
  74.     
  75.                         if (c == ANULL)
  76.                             c = NULL;
  77.     
  78.                         if (c == TAB)
  79.                             c = ARROW;
  80.     
  81.                         if (cnt < sen) {
  82.                             sav[cnt] = c;
  83.                             if (++cnt == sen)
  84.                                 for (l = 0; l < (sen-1) ; ++l)
  85.                                     crcount = writeit(sav[l], crcount);
  86.                         }
  87.     
  88.                         if (cnt == sen)
  89.                             crcount = writeit(c, crcount);
  90.                     }     
  91.                     else
  92.                         cnt = 0;
  93.     
  94.     
  95.                     oldc = c;
  96.                     c = getc(fp);
  97.                 }
  98.  
  99.                 if (cnt > 0 && cnt != sen) {
  100.                     for (l = 0; l < cnt ; ++l)
  101.                         crcount = writeit(sav[l], crcount);
  102.                 }
  103.             }
  104.         }
  105.     }
  106. }    
  107.  
  108. writeit(c, crcount)
  109. int c;
  110. int crcount;
  111. {
  112.     int justforced;
  113.  
  114.     if (c != NULL) {
  115.         if (c != '\n' || c == '\n' && justforced != 1)
  116.             putchar(c);
  117.         if (c == '\n')
  118.             crcount = -1;
  119.         if (++crcount >= 80) {
  120.             putchar('\n');
  121.             crcount = 0;
  122.             justforced = 1;
  123.         }
  124.         else
  125.             justforced = 0;
  126.     }
  127.     return (crcount);
  128. }
  129.  
  130.  
  131. atoi(s)
  132. char s[];
  133. {
  134.     int i, n;
  135.  
  136.     n = 0;
  137.     for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i)
  138.         n = 10 * n + s[i] - '0';
  139.     return(n);
  140. }
  141.  
  142.